#ifndef WIDGETEDITGUI_H
#define WIDGETEDITGUI_H

#include <QWidget>

namespace Ui {
class WidgetEditGui;
}

/**
 * @brief GUI元素属性类型
 */
enum class GuiValueType
{
    BOOLEAN, INTEGER, FLOAT, STRING, COLOR, TEXTALIGN, TEXTARRAY, ALIGN, DIRECTION, FILEPATH
};

/**
 * @brief GUI元素属性
 */
struct GuiAttribute
{
    GuiValueType type;
    QString label;
    QString name;
    QString value;
    GuiAttribute(GuiValueType _type, const QString& _label, const QString& _name, const QString& _value)
    {
        type = _type;
        label = _label;
        name = _name;
        value = _value;
    }
};

class WidgetEditGui : public QWidget
{
    Q_OBJECT

public:
    explicit WidgetEditGui(QWidget *parent = nullptr);
    ~WidgetEditGui();

signals:
    void sig_editApply(const QString& type, const QString& name, const QString& desc, const QString& evt);

public slots:
    void newGui();

private:
    void setupInput(const QString& type);

    void addRowCheck(int row, const QString& title, const QString& name, const QString& defValue = "false");
    void addRowColor(int row, const QString& title, const QString& name, const QString& defValue = "#FFFFFFFF");
    void addRowCombo(int row, const QString& title, const QString& name, const QStringList& items, std::function<void(int)> onChange, const QString& type = "string", const QString& defValue = "");
    void addRowFile(int row, const QString& title, const QString& name, const QString& filter, const QString& defValue = "");
    void addRowText(int row, const QString& title, const QString& name, const QString& type, const QString& defValue = "");

private:
    void loadAttributeMap();
    void getAttribute(const QString& type, const QString& name, QString& desc, QString& evt);

private:
    Ui::WidgetEditGui *ui;
    QMap<QString, QList<GuiAttribute>> _attributeMap;
    QMap<QString, int> _typeCountMap;
};

#endif // WIDGETEDITGUI_H
